package com.example.health_life.controller;

import com.example.health_life.Response;
import com.example.health_life.dao.MyCourse;
import com.example.health_life.service.MyCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



@RestController
public class MyCourseController {

    @Autowired
    private MyCourseService myCourseService;

    @GetMapping("/mycourses")
    public Response<List<MyCourse>> getMyCourseList(@RequestParam(required = false,defaultValue = "1")Integer status) {
        return Response.newSuccess(myCourseService.getMyCourseList(status));
    }

    @GetMapping("/mycourses/{id}")
    public Response<MyCourse> getMyCourseById(@PathVariable Integer id) {
        return Response.newSuccess(myCourseService.getMyCourseById(id));
    }

    @GetMapping("/mycourses/user/{userId}")
    public Response<List<MyCourse>> getMyCourseByUserId(@PathVariable Integer userId,
                                                        @RequestParam(required = false,defaultValue = "1") Integer status) {
        return Response.newSuccess(myCourseService.getMyCourseByUserId(userId,status));
    }
    @GetMapping("/mycourses/status")
    public Response<Integer> getMyCourseStatus(@RequestParam Integer userId, @RequestParam Integer courseId) {
        return Response.newSuccess(myCourseService.getMyCourseStatusByUserIdAndCourseId(userId, courseId));
    }

    @PostMapping("/mycourses")
    public Response<Integer> addMyCourse(@RequestBody MyCourse myCourse) {
        return Response.newSuccess(myCourseService.addMyCourse(myCourse));
    }

    @DeleteMapping("/mycourses/{id}")
    public Response<Integer> deleteMyCourse(@PathVariable Integer id) {
        return Response.newSuccess(myCourseService.deleteMyCourse(id));
    }

}
